package com.lai.laiojcodesandbox;

import com.lai.laiojcodesandbox.language.codesandbox.CCodeSandbox;
import com.lai.laiojcodesandbox.language.codesandbox.JavaCodeSandbox;
import com.lai.laiojcodesandbox.language.codesandbox.PythonCodeSandbox;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

/**
 * 代码沙箱工厂（不同语言
 */
@Component
public class CodeSandboxFactory {

    /**
     * java 代码沙箱
     */
    @Resource
    public JavaCodeSandbox javaCodeSandbox;

    /**
     * python 代码沙箱
     */
    @Resource
    public PythonCodeSandbox pythonCodeSandbox;

    /**
     * c 代码沙箱
     */
    @Resource
    public CCodeSandbox cCodeSandbox;


    /**
     * 创建代码沙箱示例
     * @param type 沙箱类型
     * @return 代码沙箱实例
     */
    public CodeSandbox newInstance(String type) {
        switch (type){
            case "java":
                return javaCodeSandbox;
            case "python":
                return pythonCodeSandbox;
            case "c":
                return cCodeSandbox;
            default:
                return new JavaCodeSandbox();
        }
    }

}
